﻿#!/usr/bin/env/ python
# -*- coding: utf-8 -*-

"""
@author: super
@software: PyCharm
@file: books
@time: 2022/1/27 14:46
"""
from commonon.logger import logger
from api.book import book
from core.result_base import ResultBase

def select_all_books(jwt):
    '''获取所有书籍'''
    resp = ResultBase()
    header = {
        "Content-Type" : "application/json",
        "Authorization": "jwt {0}".format(jwt)
    }
    resp.response = book.all_books(headers=header)
    return resp

def add_books(jwt, author, name, done):
    '''添加书籍'''
    resp = ResultBase()
    header = {
        "Content-Type" : "application/json",
        "Authorization" : "jwt {0}".format(jwt)
    }
    json_data= {
        "author": author,
        "name": name,
        "done": done
    }
    resp.response = book.add_books(json = json_data,headers = header)
    return resp

def update_books(jwt, id, author, name, done):
    '''修改书籍'''
    resp = ResultBase()
    header = {
        "Content-Type" : "application/json",
        "Authorization" : "jwt {0}".format(jwt)
    }
    json_data= {
        "author": author,
        "name": name,
        "done": done
    }
    resp.response = book.update_books(id = id, json = json_data,headers = header)
    return resp

def delete_books(jwt, id):
    '''删除书籍'''
    resp = ResultBase()
    header = {
        "Content-Type" : "application/json",
        "Authorization" : "jwt {0}".format(jwt)
    }
    resp.response = book.delete_book(id = id, headers = header)
    return resp

def select_id_book(jwt, id):
    '''根据id查看书籍'''
    resp = ResultBase()
    header = {
        "Content-Type" : "application/json",
        "Authorization" : "jwt {0}".format(jwt)
    }
    resp.response = book.id_book(id = id, headers = header)
    return resp